# -*- coding: utf-8 -*-
"""
Created on Fri Nov 15 15:23:35 2024

@author: 86151
"""
#明文预处理，输入16进制的包含16个字符的字符串即64bit明文，转为二进制序列,对比特位进行编号。
def deal_plaintext(plaintext):
     # 将十六进制字符串转换为整数
     int_value = int(plaintext, 16)
     # 将整数转换为二进制字符串，补充为64位
     binary_string = bin(int_value)[2:].zfill(64)
     return binary_string
# 初始置换表IP 64->64
IP_table = [58, 50, 42, 34, 26, 18, 10, 2,
      60, 52, 44, 36, 28, 20, 12, 4,
      62, 54, 46, 38, 30, 22, 14, 6,
      64, 56, 48, 40, 32, 24, 16, 8,
      57, 49, 41, 33, 25, 17, 9, 1,
      59, 51, 43, 35, 27, 19, 11, 3,
      61, 53, 45, 37, 29, 21, 13, 5,
      63, 55, 47, 39, 31, 23, 15, 7
      ]

# 逆置换表_IP 64->64
_IP_table = [40, 8, 48, 16, 56, 24, 64, 32, 39,
       7, 47, 15, 55, 23, 63, 31, 38, 6,
       46, 14, 54, 22, 62, 30, 37, 5, 45,
       13, 53, 21, 61, 29, 36, 4, 44, 12,
       52, 20, 60, 28, 35, 3, 43, 11, 51,
       19, 59, 27, 34, 2, 42, 10, 50, 18,
       58, 26, 33, 1, 41, 9, 49, 17, 57, 25
       ]
def ip_change(plaintext):
    # t=''
    # for i in IP:
    #     t+=plaintext[i-1]
    # return t
    return ''.join(plaintext[i - 1] for i in IP_table)


def ip_inv_change(plaintext):
    return ''.join(plaintext[i - 1] for i in _IP_table)


def process():
    plaintext=input("请输入16进制明文,不加引号!：")
    plain1=deal_plaintext(plaintext)
    plain2=ip_change(plain1)
    # print(plain2)
    # IP = '1100110000000000110011001111111111110000101010101111000010101010'
    # plain3 = ip_inv_change(IP)
    # print(plain3)
    return plain2


#示例明文'0123456789ABCDEF'
#示例输出IP'1100110000000000110011001111111111110000101010101111000010101010'

